
var realName = localStorage.getItem("realName");
if(realName){
    document.getElementById('realName').innerHTML='你好，'+realName;

    $.ajax({
        url:webConfig.webUrl+'/sseUser/getSysChildNodePermission',
        type:'post',
        success:function(arrMenuList){
            //先判断是否登录 没有登录就跳转到登录页
            if (arrMenuList.code!=webConfig.code.SUCCESS) {
                window.location.href="login.html";
            }

            var menuList = arrMenuList.result.sysChildResourceList[0].sysChildResourceList;//一级导航
            var menuStr ="";

            for (var i = 0; i < menuList.length; i++) {
                var twoNavlist = menuList[i].sysChildResourceList;//二级级导航
                var flag1=twoNavlist ?true:false;
                 menuStr+='<li>'
                        +'<a href="'+menuList[i].url+ (flag1?'" class="dropdown-toggle"':'') + '>'
                            +'<i class="menu-icon fa fa-desktop"></i>'
                            +'<span class="menu-text">'+menuList[i].name+'</span>'
                            +(flag1?'<b class="arrow fa fa-angle-down"></b>':'')
                        +'</a>'
                        +'<b class="arrow"></b>';
                if (flag1) {
                    menuStr+='<ul class="submenu">';
                    for(j =0;j<twoNavlist.length;j++)
                    {
                        var btnList = twoNavlist[j].sysChildResourceList,
                            btnStr ='';
                        var btnName='',
                            btnPosition='',
                            btnType='',
                            btnCode='';
                        if (btnList) {
                            for (var k = 0; k < btnList.length; k++) {
                                if(btnList[k].type=='button'){
                                    btnName = btnList[k].name;
                                    btnPosition = btnList[k].location;
                                    btnStr += btnName + "_" + btnPosition + "_" + btnList[k].url+'-';
                                }
                            }
                            btnStr = btnStr.substring(0, btnStr.length-1);
                        }

                        menuStr+='<li class="">'
                                    +'<a data-btns="'+btnStr+'" href="javascript:;" onclick="setIframeSrc(this);" data-title="'+menuList[i].name+'" data-url="'+twoNavlist[j].url+'">'
                                        +'<i class="menu-icon fa fa-caret-right"></i>'
                                        + twoNavlist[j].name
                                    +'</a>'
                                    +'<b class="arrow"></b>'
                                    +'</li>'
                    }
                    menuStr+='</ul>';
                 }
            }

            $('#nav-sidebar').append(menuStr+'</li>');
        }
    });
}else{
    window.location.href="login.html";
}

function setIframeSrc(obj){
    var $sideBar = $('#nav-sidebar li');
    $sideBar.removeClass('active open');
    $sideBar.find('.submenu').attr('style','');

    document.getElementById('crumb').innerHTML = obj.innerText;
    $(obj).parent().addClass('active');
    $(obj).parent('li').parent('ul').parent('li').addClass('active open');
    $("#firstcrumb").html($(obj).attr('data-title'));
    $("#mainFrame").attr("src",'html/' + $(obj).attr('data-url')+'.html?btn='+$(obj).attr('data-btns'));
}


var StatusCodeObject = {
    setArray: function(){
        var arr = [];
        $.ajax({
            url: webConfig.webUrl + '/dict/queryAllDictInfo',
            type: 'POST',
            dataType: 'json',
            async: false,
            success: function(data){
                if(data && data.result){
                    arr = data.result;
                }
            }
        });
        return arr;
    }(),
    getText: function(type,code){
        var str = '';
        for(var item in this.setArray){
            if(this.setArray[item].dictCode == code && this.setArray[item].code == type){
                str = this.setArray[item].dictDesc;
                break;
            }
        }
        return str;
    }
};

var StatusCodeObject2 = {
    setArray: function(){
        var arr = [];
        $.ajax({
            url: webConfig.webUrl + '/assetManage/selectAssetApplicationList',
            type: 'POST',
            dataType: 'json',
            async: false,
            success: function(data){
                if(data && data.result){
                    arr = data.result.list;
                }
            }
        });
        return arr;
    }(),
    getText: function(code){
        var str = '';
        for(var item in this.setArray){
            if(this.setArray[item].id == code){
                str = this.setArray[item].assetTypeName;
                break;
            }
        }
        return str;
    }
};
